using System;
using Sedge.Core.Configuration;
using Sedge.Core.Execution;
using Sedge.Core.Execution.ReportElements;
using Sedge.Core.Globalization;

namespace Sedge.UI.ViewModel
{
	public class ContactsViewModel
	{
		private readonly Suite _suite;
		private readonly Options _options;

		public string Notes
		{
			get
			{
				return _options.Notes();
			}
		}

		public ContactsViewModel(Suite suite, Options options)
		{
			_suite = suite;
			_options = options;
		}

		public void StoreData(string firstName, string lastName, string company, string email, string phone, string file)
		{
			ReportTable reportTable = new ReportTable(_suite);
			reportTable.AddRow(Locale.TemplateStrings.ContactsFirstName, firstName);
			reportTable.AddRow(Locale.TemplateStrings.ContactsLastName, lastName);
			reportTable.AddRow(Locale.TemplateStrings.ContactsCompany, company);
			reportTable.AddRow(Locale.TemplateStrings.ContactsEmail, email);
			reportTable.AddRow(Locale.TemplateStrings.ContactsPhone, phone);
			_suite.TempData[TempDataKeys.ContactsKey] = reportTable;

			if (!String.IsNullOrEmpty(file))
			{
				ReportFileList fileList = null;
				if (_suite.TempData.ContainsKey(TempDataKeys.UserFilesKey) && _suite.TempData[TempDataKeys.UserFilesKey] != null)
				{
					try
					{
						fileList = (ReportFileList) _suite.TempData[TempDataKeys.UserFilesKey];
					}
					catch
					{
						fileList = null;
					}
				}

				if (fileList == null)
				{
					fileList = new ReportFileList(_suite, false);
				}

				fileList.AddFile(file, FileType.UserFile);
				_suite.TempData[TempDataKeys.UserFilesKey] = fileList;
			}
		}
	}
}